NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Partisan Duty, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Partisan\nDuty"&vr$type=="E"] <- lb
View(vr)
reasons <- rep(c("Civic Duty","Pivotality","Group\nPivotality","Expressive\nVoting",
"Kantian","Partisan\nDuty","Social\nPressure"),3)
vr <- data.frame(reasons)
vr$mean <- NA
vr$min <- NA
vr$max <- NA
vr$type <- c(rep("E",7),rep("D",7),
rep("All",7))
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Partisan Duty, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Partisan\nDuty"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Partisan\nDuty"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Partisan\nDuty"&vr$type=="E"] <- result
#### Expressive, TREATMENT E ####
dftest <- df%>%
rename(d=y,z=treatmentE,x=vb.express)%>%
filter(treatment!="D",!is.na(x))%>%
select(d,z,x)
NT <- mean(dftest$x[dftest$z==1&dftest$d==0])
AT <- mean(dftest$x[dftest$z==0&dftest$d==1])
piNT <- mean(dftest$d[dftest$z==1]==0)
piAT <- mean(dftest$d[dftest$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dftest$x[dftest$z==0&dftest$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dftest$x[dftest$z==1&dftest$d==1])-AT*piAT)/piC
C <- C1*mean(dftest$z)+C2*(1-mean(dftest$z))
result <- C-NT
result
sims <- 10000
results <- rep(NA,sims)
set.seed(231093)
for(i in 1:sims){
dfbt <- sample_n(dftest,length(dftest$x),replace=T)
NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Expressive Voting, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Expressive\nVoting"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Expressive\nVoting"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Expressive\nVoting"&vr$type=="E"] <- result
#### Pressure, TREATMENT E ####
dftest <- df%>%
rename(d=y,z=treatmentE,x=vb.pressure)%>%
filter(treatment!="D",!is.na(x))%>%
select(d,z,x)
NT <- mean(dftest$x[dftest$z==1&dftest$d==0])
AT <- mean(dftest$x[dftest$z==0&dftest$d==1])
piNT <- mean(dftest$d[dftest$z==1]==0)
piAT <- mean(dftest$d[dftest$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dftest$x[dftest$z==0&dftest$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dftest$x[dftest$z==1&dftest$d==1])-AT*piAT)/piC
C <- C1*mean(dftest$z)+C2*(1-mean(dftest$z))
result <- C-NT
result
sims <- 10000
results <- rep(NA,sims)
set.seed(231093)
for(i in 1:sims){
dfbt <- sample_n(dftest,length(dftest$x),replace=T)
NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Social Pressure, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Social\nPressure"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Social\nPressure"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Social\nPressure"&vr$type=="E"] <- result
#### Kant, TREATMENT E ####
dftest <- df%>%
rename(d=y,z=treatmentE,x=vb.kant)%>%
filter(treatment!="D",!is.na(x))%>%
select(d,z,x)
NT <- mean(dftest$x[dftest$z==1&dftest$d==0])
AT <- mean(dftest$x[dftest$z==0&dftest$d==1])
piNT <- mean(dftest$d[dftest$z==1]==0)
piAT <- mean(dftest$d[dftest$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dftest$x[dftest$z==0&dftest$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dftest$x[dftest$z==1&dftest$d==1])-AT*piAT)/piC
C <- C1*mean(dftest$z)+C2*(1-mean(dftest$z))
result <- C-NT
result
sims <- 10000
results <- rep(NA,sims)
set.seed(231093)
for(i in 1:sims){
dfbt <- sample_n(dftest,length(dftest$x),replace=T)
NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Kant, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Kantian"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Kantian"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Kantian"&vr$type=="E"] <- result
#### Group, TREATMENT E ####
dftest <- df%>%
rename(d=y,z=treatmentE,x=vb.group)%>%
filter(treatment!="D",!is.na(x))%>%
select(d,z,x)
NT <- mean(dftest$x[dftest$z==1&dftest$d==0])
AT <- mean(dftest$x[dftest$z==0&dftest$d==1])
piNT <- mean(dftest$d[dftest$z==1]==0)
piAT <- mean(dftest$d[dftest$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dftest$x[dftest$z==0&dftest$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dftest$x[dftest$z==1&dftest$d==1])-AT*piAT)/piC
C <- C1*mean(dftest$z)+C2*(1-mean(dftest$z))
result <- C-NT
result
sims <- 10000
results <- rep(NA,sims)
set.seed(231093)
for(i in 1:sims){
dfbt <- sample_n(dftest,length(dftest$x),replace=T)
NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Group Pivotality, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Group\nPivotality"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Group\nPivotality"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Group\nPivotality"&vr$type=="E"] <- result
#### Pivotality, TREATMENT E ####
dftest <- df%>%
rename(d=y,z=treatmentE,x=vb.ir)%>%
filter(treatment!="D",!is.na(x))%>%
select(d,z,x)
NT <- mean(dftest$x[dftest$z==1&dftest$d==0])
AT <- mean(dftest$x[dftest$z==0&dftest$d==1])
piNT <- mean(dftest$d[dftest$z==1]==0)
piAT <- mean(dftest$d[dftest$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dftest$x[dftest$z==0&dftest$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dftest$x[dftest$z==1&dftest$d==1])-AT*piAT)/piC
C <- C1*mean(dftest$z)+C2*(1-mean(dftest$z))
result <- C-NT
result
sims <- 10000
results <- rep(NA,sims)
set.seed(231093)
for(i in 1:sims){
dfbt <- sample_n(dftest,length(dftest$x),replace=T)
NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Pivotality, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Pivotality"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Pivotality"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Pivotality"&vr$type=="E"] <- result
#### Civic Duty, TREATMENT E ####
dftest <- df%>%
rename(d=y,z=treatmentE,x=vb.cduty)%>%
filter(treatment!="D",!is.na(x))%>%
select(d,z,x)
NT <- mean(dftest$x[dftest$z==1&dftest$d==0])
AT <- mean(dftest$x[dftest$z==0&dftest$d==1])
piNT <- mean(dftest$d[dftest$z==1]==0)
piAT <- mean(dftest$d[dftest$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dftest$x[dftest$z==0&dftest$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dftest$x[dftest$z==1&dftest$d==1])-AT*piAT)/piC
C <- C1*mean(dftest$z)+C2*(1-mean(dftest$z))
result <- C-NT
result
sims <- 10000
results <- rep(NA,sims)
set.seed(231093)
for(i in 1:sims){
dfbt <- sample_n(dftest,length(dftest$x),replace=T)
NT <- mean(dfbt$x[dfbt$z==1&dfbt$d==0])
AT <- mean(dfbt$x[dfbt$z==0&dfbt$d==1])
piNT <- mean(dfbt$d[dfbt$z==1]==0)
piAT <- mean(dfbt$d[dfbt$z==0]==1)
piC <- 1-piNT-piAT
C1 <- ((piNT+piC)*mean(dfbt$x[dfbt$z==0&dfbt$d==0])-NT*piNT)/piC
C2 <- ((piAT+piC)*mean(dfbt$x[dfbt$z==1&dfbt$d==1])-AT*piAT)/piC
C <- C1*mean(dfbt$z)+C2*(1-mean(dfbt$z))
results[i] <- C-NT
}
resdf <- data.frame(results)
lb <- quantile(results,0.025)
ub <- quantile(results,0.975)
ggplot(resdf,aes(x=results))+
geom_vline(xintercept = 0,color="grey60")+
geom_histogram(color="grey50",fill="white")+
geom_vline(xintercept = result,color="red")+
geom_vline(xintercept = lb,color="blue")+
geom_vline(xintercept = ub,color="blue")+
ggtitle("Civic Duty, Treatment E")+
theme_bw()
vr$min[vr$reasons=="Civic Duty"&vr$type=="E"] <- lb
vr$max[vr$reasons=="Civic Duty"&vr$type=="E"] <- ub
vr$mean[vr$reasons=="Civic Duty"&vr$type=="E"] <- result
vr$reasons2 <- as.factor(vr$reasons)
print(levels(vr$reasons2))  ## This will show the levels of x are "Levels: a b c d e"
#vr$reasons2 <-  factor(vr$reasons2,levels(vr$reasons2)[c(2,5,1,6,3,4,7)])
vr$reasons2 <-  factor(vr$reasons2,levels(vr$reasons2)[c(7,4,3,6,1,5,2)])
library(plyr)
vr$reasons2 <- revalue(vr$reasons2, c("Kantian"="Kantian\nEthic"))
ggplot(vr[vr$type!="All",],aes(x=mean,y=reasons2,color=type))+
# geom_vline(xintercept = 1,color="grey50")+
geom_vline(xintercept = 0,color="grey50")+
geom_point(position=position_dodgev(height=1/2))+
geom_errorbarh(aes(xmax=max,xmin=min),height=0,
position=position_dodgev(height=1/2))+
scale_color_manual(values=c("darkgreen","skyblue3"),
name="",labels=c("\nPublicly\nExpressive\n",
"Privately\nExpressive"))+
ylab("Reasons for Voting")+
xlab("Difference in Means\n(Expressive vs. Non-Expressive Respondents)")+
theme_bw()
ggplot(vr[vr$type!="All",],aes(x=mean,y=reasons2,color=type))+
# geom_vline(xintercept = 1,color="grey50")+
geom_vline(xintercept = 0,color="grey50")+
geom_point(position=position_dodgev(height=1/2),color="skyblue3")+
geom_errorbarh(aes(xmax=max,xmin=min),height=0,
position=position_dodgev(height=1/2),color="skyblue3")+
ylab("Reasons for Voting")+
xlab("Difference in Means\n(Expressive vs. Non-Expressive Respondents)")+
theme_bw()
ggplot(res,aes(x=s1))+
geom_histogram(fill="white",color="black")+
geom_vline(xintercept = d1,color="red")+
theme_bw()
View(res)
Condition <- c("E","B")
simdim <- data.frame(Condition)
simdim$mean <- NA
simdim$q975 <- NA
simdim$q025 <- NA
set.seed(12589)
sims <- 10000
for(i in Condition){
temp <- rep(NA,sims)
for(j in 1:sims){
temp[j] <- mean(sample(df$y[df$treatment==i],
replace=T,size=sum(df$treatment==i)))
}
simdim$mean[simdim$Condition==i] <- mean(df$y[df$treatment==i],na.rm=T)
simdim$q975[simdim$Condition==i] <- quantile(temp,.975)
simdim$q025[simdim$Condition==i] <- quantile(temp,.025)
}
ggplot(simdim,aes(y=Condition,x=mean))+
geom_point(data=res,aes(x=mean,y=Condition))+
geom_errorbarh(data=simdim,aes(xmax=q975,xmin=q025),height=0)+
xlab("Opt-in Rate\n\n\n")+
scale_y_discrete(labels=c("Baseline",
"Expressive"))+
theme_bw()
set.seed(12589)
sims <- 10000
for(i in Condition){
temp <- rep(NA,sims)
for(j in 1:sims){
temp[j] <- mean(sample(df$y[df$treatment==i],
replace=T,size=sum(df$treatment==i)))
}
simdim$mean1[simdim$Condition==i] <- mean(df$y[df$treatment==i],na.rm=T)
simdim$q975[simdim$Condition==i] <- quantile(temp,.975)
simdim$q025[simdim$Condition==i] <- quantile(temp,.025)
}
ggplot(simdim,aes(y=Condition,x=mean1))+
geom_point(data=res,aes(x=mean1,y=Condition))+
geom_errorbarh(data=simdim,aes(xmax=q975,xmin=q025),height=0)+
xlab("Opt-in Rate\n\n\n")+
scale_y_discrete(labels=c("Baseline",
"Expressive"))+
theme_bw()
set.seed(12589)
sims <- 10000
for(i in Condition){
temp <- rep(NA,sims)
for(j in 1:sims){
temp[j] <- mean(sample(df$y[df$treatment==i],
replace=T,size=sum(df$treatment==i)))
}
simdim$mean[simdim$Condition==i] <- mean(df$y[df$treatment==i],na.rm=T)
simdim$q975[simdim$Condition==i] <- quantile(temp,.975)
simdim$q025[simdim$Condition==i] <- quantile(temp,.025)
}
ggplot(simdim,aes(y=Condition,x=mean))+
geom_point(data=simdim,aes(x=mean,y=Condition))+
geom_errorbarh(data=simdim,aes(xmax=q975,xmin=q025),height=0)+
xlab("Opt-in Rate\n\n\n")+
scale_y_discrete(labels=c("Baseline",
"Expressive"))+
theme_bw()
ggplot(simdim,aes(y=Condition,x=mean))+
geom_point(data=simdim,aes(x=mean,y=Condition))+
geom_errorbarh(data=simdim,aes(xmax=q975,xmin=q025),height=0)+
xlab("Opt-in Rate\n\n\n")+
scale_y_discrete(labels=c("Baseline",
"Expressive"))+
scale_x_continuous(breaks=c(.25,.5,.75))+
theme_bw()
ggsave(file="Figures/dimplotv2a.pdf",height=2.5,width=4.5)
ggsave(file="Figures/dimplotv2a.pdf",height=2.5,width=4)
ggsave(file="Figures/dimplotv2a.pdf",height=2,width=4)
ggplot(simdim,aes(y=Condition,x=mean))+
geom_point(data=simdim,aes(x=mean,y=Condition))+
geom_errorbarh(data=simdim,aes(xmax=q975,xmin=q025),height=0)+
xlab("Opt-in Rate")+
scale_y_discrete(labels=c("Baseline",
"Expressive"))+
scale_x_continuous(breaks=c(.25,.5,.75))+
theme_bw()
ggsave(file="Figures/dimplotv2a.pdf",height=2,width=4)
#### 1 LIBRARIES ####
library(tidyverse)
#### 2 IMPORT ####
cepf <- read.csv("Data/RD.csv")
cepf$fdn2 <- strptime(cepf$fdn2, format = "%Y-%m-%d")
#### 3 SAMPLE INFO ####
table(cepf$wave)
#Set number of post-plebiscite elections, depending on date of survey
cepf$elections <- 13
cepf$elections[cepf$wave<58] <- 12
cepf$elections[cepf$wave>61] <- 15
mean(cepf$elections)
#### 4 FIGURE 3 ####
sum(cepf$dist<365*15)
h <- 365*15
ggplot(cepf[cepf$dist<h,],aes(x=ym,y=pid))+
stat_summary(data=cepf[cepf$dist<h&cepf$elig==0,],
fun.y="mean", geom="point",size=1,color="gray85")+
stat_summary(data=cepf[cepf$dist<h&cepf$elig==1,],
fun.y="mean", geom="point",size=1,color="gray85")+
stat_summary(data=cepf[cepf$dist<h,],
aes(x=year),fun.y="mean", geom="point")+
stat_smooth(data=cepf[cepf$elig==1&cepf$dist<h,],method = "lm",
col = "navyblue")+
stat_smooth(data=cepf[cepf$elig==0&cepf$dist<h,],method = "lm",
col = "firebrick2")+
xlab("Date of Birth")+
scale_y_continuous(limits=c(0,1))+
ylab("Proportion Identifying with a Party")+
geom_vline(xintercept=1970.75,color="gray70",linetype=2)+
theme_bw()
#### 5 MANY BANDWIDTHS TEST - PID ####
#### 5.1 CALCULATIONS ####
## no controls
n <- seq(365,365*25,1)
beta <- rep(NA,length(n))
p <- rep(NA,length(n))
band <- data.frame(n,beta,p)
for(i in 1:length(band$n)){
n <- band$n[i]
logreg <- lm(pid~elig*diff_in_days,data=cepf[cepf$dist<n,])
band$p[i] <- summary(logreg)$coefficients[2,4]
band$beta[i] <- summary(logreg)$coefficients[2,1]
band$se[i] <- summary(logreg)$coefficients[2,2]
band$obs[i] <- summary(logreg)$df[1]+summary(logreg)$df[2]
}
bandpid <- band
## control for survey wave
n <- seq(365,365*25,1)
beta <- rep(NA,length(n))
p <- rep(NA,length(n))
band <- data.frame(n,beta,p)
for(i in 1:length(band$n)){
n <- band$n[i]
logreg <- lm(pid~elig*diff_in_days+as.factor(wave),data=cepf[cepf$dist<n,])
band$p[i] <- summary(logreg)$coefficients[2,4]
band$beta[i] <- summary(logreg)$coefficients[2,1]
band$se[i] <- summary(logreg)$coefficients[2,2]
band$obs[i] <- summary(logreg)$df[1]+summary(logreg)$df[2]
}
bandpidwave <- band
## coalition ID
n <- seq(365,365*25,1)
beta <- rep(NA,length(n))
p <- rep(NA,length(n))
band <- data.frame(n,beta,p)
for(i in 1:length(band$n)){
n <- band$n[i]
logreg <- lm(cid~elig*diff_in_days+as.factor(wave),data=cepf[cepf$dist<n,])
band$p[i] <- summary(logreg)$coefficients[2,4]
band$beta[i] <- summary(logreg)$coefficients[2,1]
band$se[i] <- summary(logreg)$coefficients[2,2]
band$obs[i] <- summary(logreg)$df[1]+summary(logreg)$df[2]
}
bandcid <- band
#### 5.2 FIGURE 4 ####
bandpid <- read.csv("Data/BW-PID.csv")
ggplot(bandpid,aes(y=beta,x=n/365))+
geom_errorbar(aes(ymax = (beta)+2*se, ymin = (beta)-2*se,width=0),
color="gray50",alpha=.01)+
geom_line()+
xlab("Bandwidth (years)")+
scale_x_continuous(breaks=seq(4,25,4),minor_breaks = seq(2,25,2),
limits=c(1,25),expand=c(0,0))+
ylab("Estimated Eligibility Effect (with 95% CI)")+
geom_hline(yintercept = 0)+
theme_bw()
#### 5.3 FIGURE A.5 ####
bandpidwave <- read.csv("Data/BW-PID-sw.csv")
